/** 
 * Forward declaration of guess API.
 * @param  num   your guess
 * @return 	     -1 if num is lower than the guess number
 *			      1 if num is higher than the guess number
 *               otherwise return 0
 * int guess(int num);
 */

class Solution {
public:
    int guessNumber(int n) {
        int m,l=1,r=n;
        while(r>l){
            m=l+floor((r-l)/2.0);
            if(guess(m)==-1){r=m;}
            else if(guess(m)==1){l=m+1;}
            else{l=m;break;}
        }
        return l;
    }
};